module.exports = app => {
 const express = require('express')
 const router = express.Router({
  mergeParams: true
 })
 /*======================== 定义接口以及方法 start ========================*/
 let result = {
  code: 200,
  msg: "请求成功"
 }
 // 创建数据
 router.post('/postList', (req, res) => {
  req.ModelData.create(req.body)
  res.json({ ...result })
 })
 // 获取数据
 router.get('/getList', async (req, res) => {
  const model = await req.ModelData.find().limit()
  res.json({ ...result, data: model })
 })
 // 修改数据
 router.post('/editList', async (req, res) => {
  // 通过传过来的body里面的数据的_id去数据库里面匹配
  const model = await req.ModelData.findByIdAndUpdate(req.body._id, req.body)
  res.json({ ...result, data: model })
 })
 // 删除数据
 router.post('/deleteList', (req, res) => {
  req.ModelData.findByIdAndDelete(req.body._id, req.body)
  res.json({ ...result })
 })
 /*======================== 定义接口以及方法 end ========================*/

 const resourceMiddleWare = async (req, res, next) => {
  req.ModelData = await require(`../models/${req.params.resource}`) // 给请求绑定原型的名称并引入数据库原型,
  next()
 }
 app.use('/api/rest/:resource', resourceMiddleWare, router)
}